{template '_header'}
<style type="text/css">
    .multi-img-details .multi-item img{height:100px;}
</style>
<div class="page-header">
    当前位置：<span class="text-primary">{if !empty($item['id'])}编辑{else}添加{/if}赠品 <small>{if !empty($item['id'])}修改【{$item['title']}】{/if}</small></span>
</div>


<div class="page-content">
    <div class="page-sub-toolbar">
        <span class="">
            {ifp 'sale.gift.add'}
                <a class='btn btn-primary btn-sm' href="{php echo webUrl('sale/gift/add',array('type'=>$type))}"><i class='fa fa-plus'></i> 添加赠品</a>
            {/if}
        </span>
    </div>
    <form {ife 'sale.gift' $item}action="" method="post"{/if} class="form-horizontal form-validate" enctype="multipart/form-data">
    <input type="hidden" name="id" value="{$item['id']}" />
    <div class="tab-content ">
        <div class="tab-pane active">
            <div class="panel-body">

                <div class="form-group">
                    <label class="col-lg control-label">排序</label>
                    <div class="col-sm-9 col-xs-12">
                        {ife 'sale.gift' $item}
                        <input type='text' class='form-control' name='displayorder' value="{$item['displayorder']}" />
                        <span class="help-block">数字越大，排名越靠前,如果为空，默认排序方式为创建时间</span>
                        {else}
                        <div class='form-control-static'>{$item['displayorder']}</div>
                        {/if}
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-lg control-label must">赠品标题</label>
                    <div class="col-sm-9 col-xs-12 ">
                        {ife 'sale.gift' $item}
                        <input type="text" id='title' name="title" class="form-control" value="{$item['title']}" data-rule-required="true"/>
                        {else}
                        <div class='form-control-static'>{$item['title']}</div>
                        {/if}
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-lg control-label">活动类型</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="hidden" name="activitytype" value="{$item['activity']}">
                        {ife 'sale.gift' $item}
                        <label class="radio-inline">
                            <input type="radio" name="activity" value="1" {if !empty($item['id'])}disabled{/if} {if empty($item['activity']) || $item['activity'] == 1}checked="true"{/if} onclick="$('#order').show();$('#product').hide();" />
                            订单金额
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="activity" value="2" {if !empty($item['id'])}disabled{/if}  {if $item['activity'] == 2}checked="true"{/if}  onclick="$('#product').show();$('#order').hide();" />
                            指定商品
                        </label>
                        <span class="help-block">赠品类型，赠品保存后无法修改，请谨慎选择</span>
                        {else}
                        <div class='form-control-static'>
                            {if $item['activity'] == 1}
                            订单金额
                            {elseif $item['activity']==2}
                            指定商品
                            {/if}</div>
                        {/if}
                    </div>
                </div>

                <div class="form-group cgt cgt-0" id="order" {if $item['activity']==2}style="display:none;"{/if}>
                <label class="col-lg control-label must">订单金额</label>
                <div class="col-sm-9 col-xs-12">
                    {ife 'sale.package' $item}
                    <div class="input-group fixsingle-input-group">
                        <input type='text' class='form-control' name='orderprice' value="{$item['orderprice']}" data-rule-required="true"/>
                        <span class="input-group-addon">元</span>
                    </div>
                    <span class="help-block image-block" style="display: block;">订单金额为赠品活动最低条件。</span>
                    {else}
                    <div class='form-control-static'>{$item['orderprice']}</div>
                    {/if}
                </div>
            </div>

            <div class="form-group" id="product" {if $item['activity']==1 || empty($item['activity'])}style="display:none;"{/if}>
            <label class="col-lg control-label">指定商品</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'sale.package' $item}
                <?php echo tpl_selector('goodsid',
                        array('multi'=>1,
                'type'=>'image',
                'placeholder'=>'指定商品名称',
                'buttontext'=>'选择商品',
                'items'=>$goods,
                'nokeywords'=>1,
                'autosearch'=>1,
                'url'=>webUrl('sale/gift/querygoods')))?>
                {else}
                {loop $goods $item}
                <a href='{php echo tomedia($item["thumb"])}' target='_blank'>
                    <img src="{php echo tomedia($item['thumb'])}" style='height:100px;border:1px solid #ccc;padding:1px;float:left;margin-right:5px;' onerror="this.src='../addons/mx_shop/static/images/nopic.png'"/>
                </a>
                {/loop}
                {/if}
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg control-label">赠品缩略图</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'sale.gift' $item}
                {php echo tpl_form_field_image2('thumb', $item['thumb']);}
                <span class="help-block image-block" style="display: block;">建议为正方型图片，尺寸建议宽度为640，如果不上传默认为第一件赠品缩略图。</span>
                {else}
                <input type="hidden" name="thumb" value="{$item['thumb']}" />
                <div class='form-control-static'>{$item['thumb']}</div>
                {/if}
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg control-label">选择赠品</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'goods' $item}
                <?php echo tpl_selector('giftgoodsid',
                        array('multi'=>1,
                'type'=>'image',
                'placeholder'=>'自定义赠品名称',
                'buttontext'=>'选择赠品',
                'items'=>$gift,
                'nokeywords'=>1,
                'autosearch'=>1,
                'url'=>webUrl('sale/gift/querygift')))?>
                <span class="help-block image-block" style="display: block;">选择指定的商品参加赠品活动。</span>
                {else}
                {loop $gift $item}
                <a href='{php echo tomedia($item["thumb"])}' target='_blank'>
                    <img src="{php echo tomedia($item['thumb'])}" style='height:100px;border:1px solid #ccc;padding:1px;float:left;margin-right:5px;' />
                </a>
                {/loop}
                {/if}
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg control-label">限时设置</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'sale.gift' $item}
                <div class="input-group">
                    <span class="input-group-addon">开始时间</span>
                    {php echo tpl_form_field_date('starttime', !empty($item['starttime']) ? date('Y-m-d H:i',$item['starttime']) :date('Y-m-d H:i'), 1)}
                    <span class="input-group-addon">结束时间</span>
                    {php echo tpl_form_field_date('endtime', !empty($item['endtime']) ? date('Y-m-d H:i',$item['endtime']) :date('Y-m-d H:i'), 1)}
                </div>
                {else}
                <div class='form-control-static'>{php echo date('Y-m-d H:i',$item['starttime'])} - {php echo date('Y-m-d H:i',$item['endtime'])}</div>
                {/if}
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg control-label">分享标题</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'sale.gift' $item}
                <input type="text" name="share_title" id="share_title" class="form-control" value="{$item['share_title']}" />
                <span class='help-block'>如果不填写，默认为赠品名称</span>
                {else}
                <div class='form-control-static'>{$item['share_title']}</div>
                {/if}
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg control-label">分享图标</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'sale.gift' $item}
                {php echo tpl_form_field_image2('share_icon', $item['share_icon'])}
                <span class='help-block'>如果不选择，默认为赠品缩略图片</span>
                {else}
                {if !empty($item['share_icon'])}
                <a href='{php echo tomedia($item['share_icon'])}' target='_blank'>
                <img src="{php echo tomedia($item['share_icon'])}" style='width:100px;border:1px solid #ccc;padding:1px' />
                </a>
                {/if}
                {/if}
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg control-label">分享描述</label>
            <div class="col-sm-9 col-xs-12">
                {ife 'sale.gift' $item}
                <textarea name="share_desc" class="form-control" rows="5" >{$item['share_desc']}</textarea>
                <span class='help-block'>如果不填写，则使用店铺名称</span>
                {else}
                <div class='form-control-static'>{$item['share_desc']}</div>
                {/if}
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg control-label">状态</label>
            <div class="col-xs-12 col-sm-8">
                <div class="input-group">
                    {ife 'sale.gift' $item}
                    <label class="radio radio-inline">
                        <input type="radio" name="status" value="1" {if intval($item['status']) ==1 }checked="checked"{/if}> 开启
                    </label>
                    <label class="radio radio-inline">
                        <input type="radio" name="status" value="0" {if intval($item['status']) ==0}checked="checked"{/if}> 关闭
                    </label>
                    {else}
                    <div class='form-control-static'>{if intval($item['status']) ==1 }开启{else}关闭{/if}</div>
                    {/if}
                </div>
            </div>
        </div>

    </div>
</div>

</div>

{ife 'sale.gift' $item}
<div class="form-group">
    <label class="col-lg control-label"></label>
    <div class="col-sm-9 col-xs-12">
        <input type="submit"  value="提交" class="btn btn-primary" />
        <a class="btn btn-default" href="{php echo webUrl('sale/gift',array('type'=>$type))}">返回列表</a>
    </div>
</div>
{/if}

</form>
</div>

{template '_footer'}